﻿using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.Globalization;

namespace SdmxMl.UiEditors
{
    public class DicoColConverter : TypeConverter
    {
        // Overrides the ConvertTo method of TypeConverter.
        public override object ConvertTo(ITypeDescriptorContext context,
            CultureInfo culture, object value, Type destinationType)
        {
            if (destinationType == typeof(string) && value is int[])
            {
                int[] arr = value as int[];
                bool isSet = false;
                string info = string.Empty;
                for (int i = 0; i < arr.Length; i++)
                {
                    if (info.Length > 0)
                        info += ", ";
                    info += arr[i].ToString();
                    if (arr[i] != 0)
                        isSet = true;
                }
                if (isSet == false)
                    info = "unused";
                return info;
            }
            return base.ConvertTo(context, culture, value, destinationType);
        }
    }
}
